package com.qs.sckill.controller;

import com.qs.sckill.entity.Goods;
import com.qs.sckill.entity.OrderInfo;
import com.qs.sckill.entity.User;
import com.qs.sckill.result.Result;
import com.qs.sckill.service.GoodsService;
import com.qs.sckill.service.OrderService;
import com.qs.sckill.vo.GoodsVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @Resource
    private GoodsService goodsService;


    @RequestMapping(value = "/orderDetail")
    public String orderDetail(Model model, User user, String orderId) {
        //用户未登录处理
        if (user == null) {
            return "redirect:/login/to_login";
        }

        OrderInfo orderInfo = orderService.getOrderById(orderId);
        model.addAttribute("orderInfo", orderInfo);
        Goods goods = goodsService.getGoodsVoByGoodsId(orderInfo.getGoodsId());
        model.addAttribute("goods", goods);
        return "order_detail";
    }
}
